package com.levy.contronller.javase.designModel.single;

/**
 * Created by levy on 2018/8/1.
 */
public class Person {

    private String name;

    private int age;

    private static Person person;
    private static Person person3 = new Person();


    //双重检查
    public static Person getPerson2Check() {
        if (person == null) {
            synchronized (Person.class) {
                if (person == null) {
                    person = new Person();
                }
            }
        }
        return person;
    }

    //懒汉模式
    public static synchronized Person getPersonLazy() {
        if (person == null) {
            person = new Person();
        }
        return person;
    }

    //饿汉模式  不用担心线程安全问题
    public static synchronized Person getPersonHungry() {
        return person3;

    }


    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }


}
